package club.mzywucai.blog.air_portal.service.impl;

import club.mzywucai.blog.air_portal.pojo.domain.JsonData;
import club.mzywucai.blog.air_portal.service.GetCodeSessionService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author mzywucai
 * @Description 获取Session中的code
 * @date 2019/6/3
 */
@Service
public class GetCodeSessionServiceImpl implements GetCodeSessionService {
    @Override
    public JsonData getCodeHistory(HttpServletRequest request) {
        HttpSession session = request.getSession();

        Object obj = session.getAttribute("fileCodeList");
        List<String> fileCodeList;
        if (null != obj) {
            fileCodeList = (List<String>) obj;

            // fileCodeList.forEach(s -> System.out.println(s));

            return JsonData.buildSuccess(0, fileCodeList, "ok");
        }

        return JsonData.buildError(-1, "code history load fail.");
    }
}
